package indi.kider.server.woniubus.service;

import indi.kider.common.model.apabus.Reservation;
import indi.kider.common.model.apabus.ReservationQuery;
import indi.kider.server.apabus.mapper.ReservationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;
import pers.vankid.common.utils.page.PageUtil;

import java.util.List;
import java.util.Map;

@Service
@SuppressWarnings("ALL")
public class ReservationServiceImpl implements ReservationService {

    @Autowired
    private ReservationMapper reservationMapper;

    @Override
    public PageResponse<List<Map>> getReservationPageList(PageRequest<ReservationQuery> request) {
        PageUtil.start(request);
        return PageUtil.getPageResponse(reservationMapper.getReservationList(request.getQuery()));
    }

    @Override
    public void reservation(Reservation reservation) {
        reservationMapper.insertSelective(reservation);
    }

    @Override
    public void updateReservationState(Reservation reservation) throws Exception{
        Reservation query = new Reservation();
        query.setId(reservation.getId());
        Reservation ret = reservationMapper.selectByPrimaryKey(query);
        if(ret.getState()!=1){
            throw new Exception("只能对预约的记录进行处理!");
        }
        reservationMapper.updateByPrimaryKeySelective(reservation);
    }
}
